package com.jiangcheng.demo.mapper;

import com.jiangcheng.demo.entity.TreeHole;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jiangcheng.demo.utils.FindArticleVo;
import com.jiangcheng.demo.utils.TreeHoleVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author admin
 * @since 2021-08-09
 */
public interface TreeHoleMapper extends BaseMapper<TreeHole> {
    // 对树洞进行分页查询 并且查出用户名 并且进行用户过滤
    @Select("SELECT t_id,title,content,tree_hole.created_time,username,is_public" +
            "            FROM tree_hole,user WHERE user.id != #{uId} " +
            "            AND user.id = tree_hole.u_id LIMIT #{start},#{pageSize}")
    List<TreeHoleVo> findArTreeHoleByPage(int start, @Param("pageSize") int pageSize, @Param("uId") int uId);

    @Select("SELECT COUNT(*) FROM tree_hole where u_id = #{uId}")
    Integer countByUid(@Param("uId") Integer uId);


    @Select("SELECT * FROM tree_hole where u_id = #{uId}")
    List<TreeHole> findTreeHoleByUid(Integer uId);
}
